package com.haima.ziliao.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.haima.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haima.common.annotation.Log;
import com.haima.common.core.controller.BaseController;
import com.haima.common.core.domain.AjaxResult;
import com.haima.common.enums.BusinessType;
import com.haima.ziliao.domain.PCelevel;
import com.haima.ziliao.service.IPCelevelService;
import com.haima.common.utils.poi.ExcelUtil;
import com.haima.common.core.page.TableDataInfo;

/**
 * 上下册管理Controller
 * 
 * @author hima
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/ziliao/celevel")
public class PCelevelController extends BaseController
{
    @Autowired
    private IPCelevelService pCelevelService;

    /**
     * 查询上下册管理列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:celevel:list')")
    @GetMapping("/list")
    public TableDataInfo list(PCelevel pCelevel)
    {
        startPage();
        List<PCelevel> list = pCelevelService.selectPCelevelList(pCelevel);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(PCelevel pCelevel,String fls)
    {
        if(StringUtils.isEmpty(fls)){
            List<PCelevel> list = pCelevelService.selectPCelevelList(pCelevel);
            return AjaxResult.success(list);
        }else{
            List<String> flss = new ArrayList<>(Arrays.asList(fls.split(",")));
            List<PCelevel> list = pCelevelService.list(new QueryWrapper<PCelevel>()
                    .in("id",flss));
            return AjaxResult.success(list);
        }
    }

    /**
     * 导出上下册管理列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:celevel:export')")
    @Log(title = "上下册管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PCelevel pCelevel)
    {
        List<PCelevel> list = pCelevelService.selectPCelevelList(pCelevel);
        ExcelUtil<PCelevel> util = new ExcelUtil<PCelevel>(PCelevel.class);
        util.exportExcel(response, list, "上下册管理数据");
    }

    /**
     * 获取上下册管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ziliao:celevel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pCelevelService.selectPCelevelById(id));
    }

    /**
     * 新增上下册管理
     */
    @PreAuthorize("@ss.hasPermi('ziliao:celevel:add')")
    @Log(title = "上下册管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PCelevel pCelevel)
    {
        return toAjax(pCelevelService.insertPCelevel(pCelevel));
    }

    /**
     * 修改上下册管理
     */
    @PreAuthorize("@ss.hasPermi('ziliao:celevel:edit')")
    @Log(title = "上下册管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PCelevel pCelevel)
    {
        return toAjax(pCelevelService.updatePCelevel(pCelevel));
    }

    /**
     * 删除上下册管理
     */
    @PreAuthorize("@ss.hasPermi('ziliao:celevel:remove')")
    @Log(title = "上下册管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pCelevelService.deletePCelevelByIds(ids));
    }
}
